package edu.nf.exam.service.impl;

import com.github.pagehelper.PageInfo;
import edu.nf.exam.dao.PaperQuestionInfoDao;
import edu.nf.exam.dao.impl.PaperQuestionInfoDaoImpl;
import edu.nf.exam.entity.PaperQuestionInfo;
import edu.nf.exam.exception.DataAcessException;
import edu.nf.exam.service.PaperQuestionService;

import java.util.List;

/**
 * @Author : QYM
 * @create 2021/6/17
 * 试题信息表--业务接口实现类
 */
public class PaperQuestionServiceImpl implements PaperQuestionService {
    @Override
    public List<PaperQuestionInfo> checkSelect(PaperQuestionInfo paperQuestionInfo) {
        PaperQuestionInfoDao dao=new PaperQuestionInfoDaoImpl();
        try {
            List<PaperQuestionInfo> list = dao.select(paperQuestionInfo);
            return list;
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("查询失败");
        }
    }

    /**
     * 根据ID查询
     * @param paperQuestionId
     * @return
     */
    @Override
    public PaperQuestionInfo selectById(Integer paperQuestionId) {
        PaperQuestionInfoDao dao=new PaperQuestionInfoDaoImpl();
        try {
            PaperQuestionInfo paperQuestionInfo = dao.selectById(paperQuestionId);
            return paperQuestionInfo;
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("查询失败");
        }
    }

    /**
     * 添加
     * @param paperQuestionInfo
     */
    @Override
    public void checkAdd(PaperQuestionInfo paperQuestionInfo) {
        try {
            PaperQuestionInfoDao dao=new PaperQuestionInfoDaoImpl();
            dao.add(paperQuestionInfo);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("添加失败");
        }
    }

    /**
     * 修改
     * @param paperQuestionInfo
     */
    @Override
    public void checkUpdate(PaperQuestionInfo paperQuestionInfo) {
        try {
            PaperQuestionInfoDao dao=new PaperQuestionInfoDaoImpl();
            dao.update(paperQuestionInfo);
        } catch (Exception e) {
            e.printStackTrace();
            throw new DataAcessException("修改失败");
        }
    }

    /**
     * 分页查询
     * @param paperQuestionId
     * @param difficult
     * @param questionType
     * @param levelName
     * @param subjectName
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public PageInfo<PaperQuestionInfo> selectByPage(Integer paperQuestionId,Integer difficult, Integer questionType, String levelName, String subjectName,Integer pageNum,Integer pageSize) {
        List<PaperQuestionInfo> list = new PaperQuestionInfoDaoImpl().selectByPage(paperQuestionId,difficult, questionType, levelName, subjectName,pageNum,pageSize);
        PageInfo<PaperQuestionInfo> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    /**
     * 查询题目月数量
     * @param createTime
     * @return
     */
    @Override
    public List<PaperQuestionInfo> selectMonthCount(String createTime) {
        List<PaperQuestionInfo> list = new PaperQuestionInfoDaoImpl().selectMonthCount(createTime);
        return list;
    }
}
